<template>
  <div class="_wz_cent_main _wz_rolesAdd">
    <Form ref="formAdd" :model="formData" label-position="right" :label-width="110" :rules="ruleValidate">
      <FormItem label="运输企业" prop="deptUuid">
        <i-select v-model="formData.deptUuid" filterable placeholder="请选择运输企业" clearable @on-change="public.selectName($event,formData,'deptName')">
          <Option v-for="item in subDeptList" :value="item.uuid" :key="item.uuid">{{ item.deptName }}</Option>
        </i-select>
      </FormItem>
      <FormItem label="角色名称" prop="roleName">
        <i-input v-model="formData.roleName" placeholder="角色名称" clearable />
      </FormItem>
      <FormItem label="角色关键字" prop="roleKey">
        <i-input v-model="formData.roleKey" placeholder="角色关键字" clearable />
      </FormItem>
      <FormItem label="备注" prop="comments">
        <i-input v-model="formData.comments" placeholder="备注" clearable type="textarea" :rows="4"/>
      </FormItem>
      <div class="demo-drawer-footer">
        <Button style="margin-right: 8px" @click="$emit('closeFun', false)">取消</Button>
        <Button type="primary" @click="addSubmit('formAdd')">提交</Button>
      </div>
    </Form>
  </div>
</template>
<script>
import menuAllot from './menuAllot.vue';
import wzTbale from "../../components/table/table";


export default {
  props: ['selectData'],
  data () {
    return {
      subDeptList: [],//运输企业
      formData: {},//新增修改表单数据
      //验证
      ruleValidate: {
        roleName: [
          { required: true, message: '请填写角色名称', trigger: 'blur' },
        ],
        roleKey: [
          { required: true, message: '请填写角色关键字', trigger: 'blur' },
        ],
      },
    }
  },
  beforeCreate () {//beforeCreate创建前状态

  },
  created () {//created创建完毕状态
  },
  beforeMount () {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程

  },
  mounted () {//mounted 挂载结束状态
    var that = this


    //运输企业
    that.axios.post(that.apiUrl.coreDeptCoreDeptList, {}).then(res => {
      if (!!res) {
        that.subDeptList = res.data.data;
      }
    }).catch(err => {
      console.log("失败", err)
    })

    that.formData = that.selectData;

  },
  methods: {//执行的方法
    addSubmit (name) {//新增修改提交
      var that = this
      that.$refs[name].validate((valid) => {
        if (valid) {//正则判断使用
          that.$Spin.show()
          that.axios.post(that.apiUrl.systemRoleSystemRoleSaveOrUpdate, that.formData).then(res => {
            that.$Spin.hide()
            if (!!res) {
              that.$Message.success('保存成功.')
              that.$emit("closeFun", true)
            }
          }).catch(err => {
            console.log("失败", err)
          })

        } else {
          this.$Message.error('请正确填写表单')
        }
      })
    },
  },
  watch: {//监听

  },
  beforeUpdate () {//beforeUpdate 更新前状态

  },
  updated () {//updated 更新完成状态

  },
  beforeDestroy () {//beforeDestroy 销毁前状态

  },
  destroyed () {//destroyed 销毁完成状态

  }
}
</script>
<style lang="less">
._wz_rolesAdd {

}
</style>
